package com.ruoyi.common.utils;

import java.util.regex.Pattern;

/**
 * 合法相关工具类.
 *
 * @author ruoyi
 */
public class ValidatorUtils
{
    /**
     * 中国车牌号码（兼容新能源车牌）
     */
    private static String PLATE_NUMBER_REGEX =
            //https://gitee.com/dromara/hutool/issues/I1B77H?from=project-issue
            "^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[ABCDEFGHJK])|([ABCDEFGHJK]([A-HJ-NP-Z0-9])[0-9]{4})))|" +
                    //https://gitee.com/dromara/hutool/issues/I1BJHE?from=project-issue
                    "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]\\d{3}\\d{1,3}[领])|" +
                    "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$";

    /**
     * 中国车牌号码（兼容新能源车牌）
     */
    private final static Pattern PLATE_NUMBER = Pattern.compile(PLATE_NUMBER_REGEX);

    public static boolean validateCarNumber(String value) {
        return PLATE_NUMBER.matcher(value).matches();
    }

}
